var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("RoleSoldierInfo"),
    l = cc._decorator,
    _ = l.ccclass,
    c = l.property,
    d = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.choose_light_node = null),
                (t.role_head_sprite = null),
                (t.role_die_node = null),
                (t.my_hp_bar_node = null),
                (t.other_hp_bar_node = null),
                (t.equip_sprite = []),
                (t.role_info = null),
                (t.match_player_info = null),
                (t.max_hp = 0),
                (t.have_hp = 0),
                (t.role_index = 0),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () { }),
            (t.prototype.addEvent = function () {
                this.attachEvent(n.default.SEND_PLAYER_CHOOSE_OPERATE_HERO_INDEX, this.showChooseHero, this),
                    this.attachEvent(n.default.SEND_D_HERO_BE_HIT_INFO, this.updateHeroBeHitInfo, this);
            }),
            (t.prototype.showLeftHeroInfo = function (e) {
                if (
                    ((this.role_info = i.GlobalParams.GamePlayerInfo[e]),
                        (this.role_index = e),
                        (this.match_player_info = i.GlobalParams.MatchGamePlayer[e]),
                        (this.node.active = this.role_info.hp > 0),
                        (this.choose_light_node.active = 0 == e),
                        (this.max_hp = this.role_info.hp + i.GlobalParams.BuyEquipInfo[e].hp),
                        (this.have_hp = this.max_hp),
                        (this.role_die_node.active = !1),
                        this.showHeroEquip(),
                        this.role_info.hp > 0)
                ) {
                    var t = "hero_" + s.default.Role_info[this.match_player_info.role_id].id;
                    (this.role_head_sprite.spriteFrame = r.default.getInstance().getGameHoreHeadFrame(t)),
                        this.updateHeroHpInfo(0);
                }
                this.showChooseHero();
            }),
            (t.prototype.showChooseHero = function () {
                (this.choose_light_node.active = this.role_index == i.GlobalParams.MatchMyIndex),
                    (this.my_hp_bar_node.active = this.choose_light_node.active),
                    (this.other_hp_bar_node.active = !this.choose_light_node.active);
            }),
            (t.prototype.showHeroEquip = function () {
                for (var e = 0; e < this.equip_sprite.length; e++)
                    this.equip_sprite[e].spriteFrame = r.default
                        .getInstance()
                        .getEquipIconFrame("equip_" + this.match_player_info.equip_info[e]);
            }),
            (t.prototype.updateHeroBeHitInfo = function (e, t) {
                t.index == this.role_index && this.updateHeroHpInfo(-1 * t.hit_hp);
            }),
            (t.prototype.updateHeroHpInfo = function (e) {
                (this.have_hp += e),
                    (this.have_hp = this.have_hp > this.max_hp ? this.max_hp : this.have_hp),
                    (this.have_hp = this.have_hp < 0 ? 0 : this.have_hp),
                    (this.other_hp_bar_node.width = this.my_hp_bar_node.width = (125 * this.have_hp) / this.max_hp),
                    this.have_hp <= 0 && (this.role_die_node.active = !0);
            }),
            oo([c(cc.Node)], t.prototype, "choose_light_node", void 0),
            oo([c(cc.Sprite)], t.prototype, "role_head_sprite", void 0),
            oo([c(cc.Node)], t.prototype, "role_die_node", void 0),
            oo([c(cc.Node)], t.prototype, "my_hp_bar_node", void 0),
            oo([c(cc.Node)], t.prototype, "other_hp_bar_node", void 0),
            oo([c(cc.Sprite)], t.prototype, "equip_sprite", void 0),
            oo([_], t)
        );
    })(a.default);
o.default = d;
